﻿using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;

namespace WebHouseTypeAPI.Controllers
{
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class UploadController : ControllerBase
    {
        public UploadController(IWebHostEnvironment web)
        {
            Web = web;
        }

        public IWebHostEnvironment Web { get; }

        [HttpPost]
        public IActionResult UpLock(IFormFile file)
        {

            try
            {
                var id = Guid.NewGuid().ToString() + file.FileName;

                string path = Web.WebRootPath + @"\pic\" + id;

                using (FileStream fs = System.IO.File.Create(path))
                {

                    file.CopyTo(fs);
                    fs.Close();

                }

                var p = "/pic/" + id;
                return Ok(p);

            }
            catch (Exception)
            {

                throw;
            }
           
        }



    }
}
